Skip to content

server.js: Refactor profile server code into own file#4656

Merged
julienw merged 8 commits into
firefox-devtools:mainfrom
kazarmy:separate-launch-fp-process
Oct 3, 2023
Merged

server.js: Refactor profile server code into own file#4656
julienw merged 8 commits into
firefox-devtools:mainfrom
kazarmy:separate-launch-fp-process

Conversation

@kazarmy

@kazarmy kazarmy commented Jun 4, 2023

Copy link
Copy Markdown
Contributor

As per #4452 (review), this PR pulls out the profile server code in server.js into a separate script that spawns a local profiler server via server.js and opens the profiler with a from-url URL. Yes, it's definitely more interesting, though things get more complicated when one can't share information through the same address space. Not sure whether the code can't be simplified.

Some notes:

  1. The script is .mjs due to the conveniences of top-level await and easy importing of the open package.
  2. The modification to .eslintrc.js is for ESLint to recognize node:http as a valid Node module.

@codecov

codecov Bot commented Jun 4, 2023

Copy link
Copy Markdown

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (373e448) 88.32% compared to head (10c3e92) 88.32%.
Report is 2 commits behind head on main.

❗ Current head 10c3e92 differs from pull request most recent head ab85b71. Consider uploading reports for the commit ab85b71 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4656   +/-   ##
=======================================
  Coverage   88.32%   88.32%           
=======================================
  Files         300      300           
  Lines       26808    26808           
  Branches     7242     7241    -1     
=======================================
  Hits        23679    23679           
  Misses       2917     2917           
  Partials      212      212           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@julienw julienw self-requested a review August 8, 2023 11:41

@julienw julienw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kazarmy! I'm so sorry I didn't look at this earlier.
I believe this is solid work! But as you said yourself too, this looks a bit complicated compared to what we have already. I looked at it and tried to find ways to make it less complicated but I believe that's not really possible. Therefore I think that in this current form, this doesn't bring very useful improvements over the current situation.

I can think of another possibility: have a script that would only spawn a server serving a file + open a tab, but no launching the profiler UI.
I can imagine that this functionality would be in a importable file so that it can be used in the server.js (replacing some of that existing code) and could also be imported from a script.

This would simplify server.js (because the http server spawn would be in a different file) and provide the functionality of opening the profiler UI loading some local file even if the server is already launched.

I also believe this would be simpler because there wouldn't need to do all the complex work around temporary config files.

What do you think?

Comment thread .eslintrc.js Outdated
],
extensions: ['.js', '.jpg'],
},
node: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error did you get without that? I don't see an error when I remove this locally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import-resolver-node-true
with the branch at 91b485c.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I know, yarn lint-js doesn't look at *.mjs but just *.js... So this file wasn't checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it should have ... I haven't yet found a good CommonJS equivalent to top-level await.

@kazarmy

kazarmy commented Sep 19, 2023

Copy link
Copy Markdown
Contributor Author

Funny, this PR's base branch separate-launch-fp-process has changed but GitHub isn't picking up the changes.

@kazarmy kazarmy changed the title server.js: Open local from-url URL in separate script server.js: Refactor profile server code into own file Sep 19, 2023
@kazarmy

kazarmy commented Sep 19, 2023

Copy link
Copy Markdown
Contributor Author

Progress on this PR is a tad unexpected but thanks for the compliment and review! Hopefully I haven't forgotten significant amounts of JavaScript in the meantime.

I can think of another possibility: have a script that would only spawn a server serving a file + open a tab, but no launching the profiler UI.

Not sure what you mean by "open a tab", but if you're implying that the profile server should eventually be a gateway to multiple local profile files, that would probably require some more thinking in a different PR.

What do you think?

Assuming that I have interpreted your words correctly, I'm ok with simplifications like 24c73d5 (not sure whether a class is needed here) as long as people are happy with it even without an immediate follow-up.

@julienw

julienw commented Sep 26, 2023

Copy link
Copy Markdown
Contributor

I can think of another possibility: have a script that would only spawn a server serving a file + open a tab, but no launching the profiler UI.

Not sure what you mean by "open a tab", but if you're implying that the profile server should eventually be a gateway to multiple local profile files, that would probably require some more thinking in a different PR.

Sorry for not being super clear.

I meant:

  • spawn a server serving the file + opening a tab to the profiler UI (with the open tool), but not launching the profiler UI server.

(I'm writing this comment before looking at your code, doing it now...)

@julienw julienw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, we can merge it this way and then maybe somebody else can take it from there :) I can imagine you'd like to move on !

Comment thread server.js Outdated
)}`;
// Start profile server and open on profile.
profileServer.start(host, profilerUrl, argv.profile, (profileFromUrl) => {
import('open').then((open) => open.default(profileFromUrl, openOptions));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The open part could go to the utility function too. The utility could be called serveAndOpen

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the dual responsibility, this makes sense and it doesn't seem reasonable to punt this to a follow-up salami slice PR so f9ce3fd

@julienw

julienw commented Sep 27, 2023

Copy link
Copy Markdown
Contributor

Just waiting for your answer before we merge it!

@kazarmy

kazarmy commented Sep 27, 2023

Copy link
Copy Markdown
Contributor Author

Sorry for not being super clear.
I meant:

Oh ok yeah I can miss the obvious so being super clear is great! I'll try so that being super clear isn't required though.

Just waiting for your answer before we merge it!

I suppose you have to reapprove now?

@julienw julienw enabled auto-merge (squash) October 3, 2023 09:50
@julienw

julienw commented Oct 3, 2023

Copy link
Copy Markdown
Contributor

Thanks again for your patience!

@julienw julienw merged commit 9406a98 into firefox-devtools:main Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants